package com.cjx.api.model.enums;

import lombok.Getter;
import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户接口调用状态枚举
 *
 * @author cjx
 *
 */
@Getter
public enum InterfaceStatusEnum {

    /**
     * 用户接口调用状态枚举
     */
    INTERFACE_ONLINE("上线", 1),
    INTERFACE_OFFLINE("下线", 0);


    private final String status;

    private final int value;

    InterfaceStatusEnum(String status, int value) {
        this.status = status;
        this.value = value;
    }

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<String> getValues() {
        return Arrays.stream(values()).map(item -> String.valueOf(item.value)).collect(Collectors.toList());
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static InterfaceStatusEnum getEnumByValue(int value) {
        if (ObjectUtils.isEmpty(value)) {
            return null;
        }
        for (InterfaceStatusEnum anEnum : InterfaceStatusEnum.values()) {
            if (anEnum.value == value) {
                return anEnum;
            }
        }
        return null;
    }

}
